from django.db import models
# 导入时间域
from django.utils import timezone


# Create your models here.

# 基类
class Base(models.Model):
    # 创建时间
    create_time = models.DateTimeField(default=timezone.now, null=True)

    class Meta:
        abstract = True


# 会员等级
class Role(models.Model):
    name = models.CharField(verbose_name='会员', max_length=255)
    # 状态
    state = models.IntegerField(default=0)

    class Meta:
        db_table = 'role'


# 用户表
class UserModel(Base):
    username = models.CharField("用户名", max_length=50)
    password = models.CharField("密码", max_length=200)
    role = models.ForeignKey(Role, on_delete=models.CASCADE, default='普通会员')
    money = models.CharField(verbose_name='钱', max_length=255, default=0)
    name = models.CharField("姓名", max_length=50)
    phone = models.CharField("手机号", max_length=50)
    idcard = models.CharField("身份证", max_length=50)
    address = models.CharField("地址", max_length=200)

    class Meta:
        db_table = 'user'
        verbose_name = '用户表'
        verbose_name_plural = verbose_name


# 充值
class Recharge(models.Model):
    PAY_METHOD = (
        (1, "支付宝"),
        (2, "微信"),
        (3, "Pay"),
    )
    ORDER_STATUS = (
        (1, "待充值"),
        (2, "已充值"),
        (3, "已取消"),
    )
    user = models.ForeignKey(UserModel, on_delete=models.PROTECT, verbose_name="充值用户")
    order_id = models.CharField('订单号', max_length=124)
    trade_no = models.CharField('支付宝订单号', max_length=132, null=True)  # 28位
    pay_time = models.DateTimeField('充值时间', null=True)
    pay_method = models.CharField('充值方式', choices=PAY_METHOD, default=1, max_length=8)
    status = models.CharField('充值状态', choices=ORDER_STATUS, default=1, max_length=8)
    total_amount = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="充值金额")

    class Meta:
        db_table = '充值支付'

    def __str__(self):
        return self.order_id


# 订单表二
class OrderModel(models.Model):
    uid = models.CharField("用户ID", max_length=50)
    shop_name = models.CharField('商品名称', max_length=50)
    shop_price = models.CharField('支付金额', max_length=50)
    order_date = models.DateField("当前日期", auto_now_add=True)
    order_number = models.CharField('订单号', max_length=200)
    state = models.CharField('支付状态', max_length=50, null=True)
    num = models.IntegerField()
    class Meta:
        db_table = '订单'

    def __str__(self):
        return self.shop_name
